//
//  LoginViewController.m
//  Teacher
//
//  Created by cong on 15/10/28.
//  Copyright © 2015年 liangdianxiong. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "AFHTTPSessionManager.h"
@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *tf_number;
@property (weak, nonatomic) IBOutlet UITextField *tf_password;
@property (weak, nonatomic) IBOutlet UIButton *bt_login;
@property (weak, nonatomic) IBOutlet UIButton *bt_forgetPassword;
@property (weak, nonatomic) IBOutlet UIButton *bt_register;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"haohao";
    _tf_number.placeholder=@"请输入手机号码/帐号";
    
    [_tf_number setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
   _tf_number.font = [UIFont fontWithName:@"Arial" size:25.0f];
    _tf_password.placeholder=@"请输入密码";
    [_tf_password setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    _tf_password.font=[UIFont fontWithName:@"Arial" size:25.0f];
    
    [_bt_login addTarget:self action:@selector(loginSuecc:) forControlEvents:UIControlEventTouchUpInside];
    [_bt_register addTarget:self action:@selector(registe:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)loginSuecc:(UIButton *)sender{
    
//  http://api.tjdianping.com/user/userinfo/phone/18820039356/format/xml
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
    
    
    [manager GET:@"http://api.tjdianping.com/user/userinfo/phone/18820039356/format/xml" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        
        //NSData 转NSString
        NSString *result  =[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        
        
        NSDictionary * dict = [self  dictionaryWithJsonString:result];
        NSLog(@"%@",dict);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
   
}

-(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil) {
        
        return nil;
        
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError *err;
    
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                         
                                                        options:NSJSONReadingMutableContainers
                         
                                                          error:&err];
    
    if(err) {
        
        NSLog(@"json解析失败：%@",err);
        
        return nil;
        
    }
    
    return dic;
    
}
-(void)registe:(UIButton *)sender{
    RegisterViewController *Register=[self.storyboard instantiateViewControllerWithIdentifier:@"RegisterViewController"];
    [self presentViewController:Register animated:YES completion:nil];
    
    
}




@end

